#include <am.h>
#include <klib.h>
#include <klib-macros.h>

#define IP_BASE_ADDR 0x0F000000
#define IP_OFFSET 0x1FFF

int main(){
    putstr("sram test\n");
    uint32_t *prog = (uint32_t *)IP_BASE_ADDR;
    for(int i = 0; i < 10; ++i) {
        *prog = (uint8_t)i;
        ++prog;
    }
    uint32_t *addr = (uint32_t *)(IP_BASE_ADDR);
    for(int i = 0; i < 10; ++i) {
        uint32_t val = *addr;
        if (val != (uint8_t) i) {
            putstr("fail\n");
        }
        ++addr;
    }
    putstr("check uint8 done\n");

    prog = (uint32_t *)IP_BASE_ADDR;
    for(int i = 0; i < 10; ++i) {
        *prog = (uint16_t)i;
        ++prog;
    }
    addr = (uint32_t *)(IP_BASE_ADDR);
    for(int i = 0; i < 10; ++i) {
        uint32_t val = *addr;
        if (val != (uint16_t)i) {
            // printf("%d fail sram: %u orgn: %u\n", i, val, (uint32_t)i);
            putstr("fail\n");
        }
        ++addr;
    }
    putstr("check uint16 done\n");

    prog = (uint32_t *)IP_BASE_ADDR;
    for(int i = 0; i < 10; ++i) {
        *prog = (uint32_t)i;
        ++prog;
    }
    addr = (uint32_t *)(IP_BASE_ADDR);
    for(int i = 0; i < 10; ++i) {
        uint32_t val = *addr;
        if (val != (uint32_t)i) {
            // printf("%d fail sram: %u orgn: %u\n", i, val, (uint32_t)i);
            putstr("fail\n");
        }
        ++addr;
    }
    putstr("check uint32 done\n");

    prog = (uint32_t *)IP_BASE_ADDR;
    for(int i = 0; i < 600; ++i) {
        *prog = (uint64_t)i;
        ++prog;
    }
    addr = (uint32_t *)(IP_BASE_ADDR);
    for(int i = 0; i < 600; ++i) {
        uint32_t val = *addr;
        if (val != (uint64_t)i) {
            // printf("%d fail sram: %u orgn: %u\n", i, val, (uint32_t)i);
            putstr("fail\n");
        }
        ++addr;
    }
    putstr("check uint64 done\n");

    return 0;
}
